const runeColumns = [
  { label: '铭文1', prop: 'lose_equip_map_1', width: '360px' },
  { label: '铭文2', prop: 'lose_equip_map_2', width: '360px' },
  { label: '铭文3', prop: 'lose_equip_map_3', width: '360px' },
  { label: '铭文4', prop: 'lose_equip_map_4', width: '360px' },
  { label: '铭文5', prop: 'lose_equip_map_5', width: '360px' },
  { label: '铭文6', prop: 'lose_equip_map_6', width: '360px' },
]

// 装备列配置
const equipmentColumns = [
  { label: '头盔', prop: 'def_equip_map_1', width: '360px' },
  { label: '衣服', prop: 'def_equip_map_2', width: '360px' },
  { label: '护手', prop: 'def_equip_map_3', width: '360px' },
  { label: '戒指', prop: 'def_equip_map_4', width: '360px' },
]

// 淬炼属性列配置
const quenchingColumns = [
  { label: '头盔淬炼属性', prop: 'def_equip_map_1_attrs', width: '250px' },
  { label: '衣服淬炼属性', prop: 'def_equip_map_2_attrs', width: '250px' },
  { label: '护手淬炼属性', prop: 'def_equip_map_3_attrs', width: '250px' },
  { label: '戒指淬炼属性', prop: 'def_equip_map_4_attrs', width: '250px' },
]
const baseColumns = [
  { prop: 'sname', label: '服务器', width: '100', fixed: true, align: 'center' },
  { prop: 'actor_id', label: '角色ID', width: '100', fixed: true, align: 'center' },
  { prop: 'hero_id', label: '英雄ID', width: '120', sortable: 'custom', align: 'center' },
  { prop: 'last_update_time', label: '最后更新时间', width: '135', align: 'center' },
  { prop: 'best', label: '最强五人', width: '60', align: 'center', formatter: (row) => row.best === 1 ? '是' : '否' },
  { prop: 'quality', label: '品质ID', width: '80', sortable: 'custom', align: 'center' },
  { prop: 'fight', label: '英雄战力', width: '100', sortable: 'custom', align: 'center' },
  { prop: 'level', label: '英雄等级', width: '80', sortable: 'custom', align: 'center' },
  { prop: 'stage', label: '英雄阶级', width: '100', sortable: 'custom', align: 'center' },
  { prop: 'star', label: '英雄星级', width: '100', sortable: 'custom', align: 'center' },
  {
    label: '生命',
    width: '80',
    align: 'center',
    prop: 'attrs_1',
    formatter: (row) => row.attrs?.[1] || '-'
  },
  {
    label: '攻击',
    width: '80',
    align: 'center',
    prop: 'attrs_3',
    formatter: (row) => row.attrs?.[3] || '-'
  },
  {
    label: '防御',
    width: '80',
    align: 'center',
    prop: 'attrs_5',
    formatter: (row) => row.attrs?.[5] || '-'
  },
  {
    label: '产能',
    width: '80',
    align: 'center',
    prop: 'attrs_35',
    formatter: (row) => row.attrs?.[35] || '-'
  },
  { prop: 'weapon_level', label: '源器强化等级', width: '120', sortable: 'custom', align: 'center' },
  { prop: 'weapon_stage', label: '源器突破等级', width: '120', sortable: 'custom', align: 'center' },
]

export default function getActorHerorField(is_log) {
  let columns = baseColumns
  if (is_log === 1) {
    const logDateColumn = {
      fixed: true,
      label: '记录时间',
      prop: 'log_date',
      sortable: 'custom',
      width: '150',
      align: 'center',
    }
    // 插入到第一列
    columns.unshift(logDateColumn)
  }
  columns = columns.map(item => ({ ...item, group: 'base' }))
  console.log(runeColumns)
  const truneColumns = runeColumns.map(item => ({ ...item, group: 'rune', formatter: formatRune }))
  const tequipmentColumns = equipmentColumns.map(item => ({ ...item, group: 'equipment', formatter: formatEquipment }))
  const tquenchingColumns = quenchingColumns.map(item => ({ ...item, group: 'quenching', formatter: formatQuenching }))
  const allColumns = [
    ...columns,
    ...truneColumns,
    ...tequipmentColumns,
    ...tquenchingColumns
  ]
  return allColumns
}

function formatRune(row, column) {
  const prop = column.prop || column.property
  if (row[prop]) {
    return `唯一ID：${row[prop].uuid}, 道具：${row[prop].equipId}, 强化等级：${row[prop].level}`
  }
  return ''
}
function formatEquipment(row, column) {
  const prop = column.prop || column.property
  if (row[prop]) {
    return `唯一ID：${row[prop].uuid}, 道具：${row[prop].equipId}, 强化等级：${row[prop].level}`
  }
  return ''
}
function formatQuenching(row, column) {
  const prop = column.prop || column.property
  if (row[prop] && row[prop].attrs) {
    const attrs = JSON.stringify(row[prop].attrs) // 深拷贝为普通对象
    return attrs
  }
  return ''
}
